from django.conf import settings
from django.contrib import admin
from django.contrib.auth import admin as auth_admin
from django.contrib.auth import get_user_model
from django.utils.html import mark_safe
from django.contrib.auth.models import Group

from .models import Company


class ProxyGroup(Group):
    class Meta:
        proxy = True
        verbose_name = '组'
        verbose_name_plural = verbose_name


admin.site.unregister(Group)
admin.site.register(ProxyGroup, auth_admin.GroupAdmin)

User = get_user_model()


@admin.register(User)
class UserAdmin(auth_admin.UserAdmin):
    # form = UserChangeForm
    # add_form = UserCreationForm
    # fieldsets = (("User", {"fields": ("email",)}),) + auth_admin.UserAdmin.fieldsets
    list_display = ["username", "email", "full_name", "is_active",  "is_superuser", "date_joined", "last_login"]
    search_fields = ["email", "username"]


@admin.register(Company)
class CompanyAdmin(admin.ModelAdmin):
    list_display = ["name"]


admin.site.site_title = settings.ADMIN_SITE_TITLE
admin.site.site_header = mark_safe(f'<img src="/static/images/{settings.ADMIN_SITE_HEADER_LOGO}" '
                                   f'style="{settings.ADMIN_SITE_HEADER_LOGO_STYLE}">    '
                                   f'{settings.ADMIN_SITE_TITLE}')
admin.site.index_title = settings.ADMIN_INDEX_TITLE
